package com.bawei.module_inspection

import android.os.Bundle
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.state.Empty
import com.bawei.lib_common.base.state.Failed
import com.bawei.lib_common.base.state.Loading
import com.bawei.lib_common.base.state.Success
import com.bawei.module_inspection.adapter.InspectionAdapter
import com.bawei.module_inspection.databinding.ActivityInspectionBinding
import com.bawei.module_inspection.ui.InspectionViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch

@AndroidEntryPoint
@Route(path = Router.Ui.InspectionActivity)
class InspectionActivity : BaseActivity<InspectionViewModel, ActivityInspectionBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_inspection
    override val mViewModel: InspectionViewModel by viewModels()
    private val mInspectionAdapter by lazy { InspectionAdapter() }

    override fun initView() {
        mBinding.rvInspection.apply {
            adapter = mInspectionAdapter
            layoutManager = LinearLayoutManager(this@InspectionActivity)
        }

        mBinding.fabAdd.setOnClickListener {
            ARouter.getInstance().build(Router.Ui.InspectionAddActivity).navigation()
        }
    }

    override fun initListener() {
        mViewModel.getInspection()
    }


    override fun initData() {
        lifecycleScope.launch {
            mViewModel.mInspectionState.collect{
                mInspectionAdapter.submitList(mViewModel.mInspectionListData)
            }
        }
    }

    override fun onResume() {
        super.onResume()
        mViewModel.getInspection()
    }

}